#include "MenuScene.h"
#include "PlayScene.h"

USING_NS_CC;

Scene* MenuScene::createScene()
{
	// 'scene' is an autorelease object
	auto scene = Scene::create();

	// 'layer' is an autorelease object
	auto layer = MenuScene::create();

	// add layer as a child to scene
	scene->addChild(layer);

	// return the scene
	return scene;
}

// on "init" you need to initialize your instance
bool MenuScene::init()
{
	//////////////////////////////
	// 1. super init first
	if ( !Layer::init() )
	{
		return false;
	}

	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	auto centerpos = visibleSize / 2;

	auto spritebg = Sprite::create("helloBG.png");
	spritebg->setPosition(centerpos);
	this->addChild(spritebg);

	MenuItemFont::setFontSize(60);

	////auto menuItemPlay = MenuItemImage::create("start_n", "start_s", "start_n", CC_CALLBACK_1(MenuScene::OnPlay, this));
	//auto menuItemPlay = MenuItemImage::create(
	//	"CloseNormal.png",
	//	"CloseSelected.png",
	//	CC_CALLBACK_1(MenuScene::OnPlay, this));
	//auto menu = Menu::create(menuItemPlay, NULL);
	//this->addChild(menu);

	auto menuItemPlay = MenuItemImage::create("start_n", "start_s", CC_CALLBACK_1(MenuScene::OnPlay, this));

	menuItemPlay->setPosition(Vec2(origin.x + visibleSize.width - menuItemPlay->getContentSize().width/2 ,
		origin.y + menuItemPlay->getContentSize().height/2));

	auto menu = Menu::create(menuItemPlay, NULL);
	menu->setPosition(Vec2::ZERO);

	this->addChild(menu);


	return true;
}

void MenuScene::OnPlay(Ref* pSender)
{
	// log(" ==OnPlay clicked");
	
	auto playScene = PlayScene::createScene();
	Director::getInstance()->replaceScene(playScene);
}
